package com.financing.wap.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.financing.wap.common.SqlName;
import com.financing.wap.dao.IAuthenticationDao;
import com.financing.wap.dto.AuthenticationDTO;
import com.financing.wap.dto.CertDTO;

@Repository("authenticationDao")
@SuppressWarnings(value={"unchecked", "deprecation"})
public class AuthenticationDaoImpl extends BaseDaoImpl<AuthenticationDTO, Integer> implements IAuthenticationDao  {

	@Override
	public Class<AuthenticationDTO> getEntityClass() {
		return AuthenticationDTO.class;
	}
	
	@Override
	public boolean submitAuthInfo(AuthenticationDTO auth) {
		
		try{
//			this.sqlMapClientTemplate.delete(SqlName.AUTHENTICATION_DELETE,auth);
			this.sqlMapClientTemplate.insert(SqlName.AUTHENTICATION_SUBMIT, auth);
			return true;
		}catch(Exception e){
			log.error("error when submit auth info", e);
			return false;
		}
	}

	@Override
	public boolean submitCertInfo(CertDTO cert) {
		try{
			this.sqlMapClientTemplate.insert(SqlName.AUTHENTICATION_CERT_SUBMIT, cert);
			return true;
		}catch(Exception e){
			log.error("error when submit  cert info", e);
			return false;
		}
	}

	@Override
	public AuthenticationDTO queryAuthInfo(String faId) {
		List<AuthenticationDTO> authenticationDTOList =  sqlMapClientTemplate.queryForList(SqlName.AUTHENTICATION_AUTH_QUERY, faId);
		if(authenticationDTOList!=null && !authenticationDTOList.isEmpty()){
			return authenticationDTOList.get(0);
		}
		return new AuthenticationDTO(); 
	}

	@Override
	public List<CertDTO> queryCertList(String faId) {
		
		return (List<CertDTO>) sqlMapClientTemplate.queryForList(SqlName.AUTHENTICATION_CERT_LIST, faId);
	}

	@Override
	public boolean deleteCertInfo(String faId) {
		try{
			this.sqlMapClientTemplate.delete(SqlName.AUTHENTICATION_CERT_DELETE,faId);
			return true;
		}catch(Exception e){
			log.error("error when submit  cert info", e);
			return false;
		}
	}

	@Override
	public boolean authenticationUpdate(AuthenticationDTO auth) {
		this.sqlMapClientTemplate.update(sqlName.authenticationUpdate,auth);
		return true;
	}

}
